import request from '@/utils/request'

export const login = data => request.post('/admin/login', data, { loading: true })

export const bannerList = data => request.get('/admin/banner', data, { loading: true })
export const bannerUpdate = data => {
  if (data.id) {
    return request.put(`/admin/banner/${data.id}`, data, { loading: true })
  }
  return request.post('/admin/banner', data, { loading: true })
}
export const bannerDelete = id => {
  if ('number' === typeof id) {
    return request.delete(`/admin/banner/${id}`, {}, { loading: true })
  }
  return request.delete(`/admin/banner/batch`, { id }, { loading: true })
}

export const newsCategoryList = data => request.get('/admin/news/category', data, { loading: true })
export const newsCategoryUpdate = data => {
  if (data.id) {
    return request.put(`/admin/news/category/${data.id}`, data, { loading: true })
  }
  return request.post('/admin/news/category', data, { loading: true })
}
export const newsCategoryDelete = id => {
  if ('number' === typeof id) {
    return request.delete(`/admin/news/category/${id}`, {}, { loading: true })
  }
  return request.delete(`/admin/news/category/batch`, { id }, { loading: true })
}

export const newsList = data => request.get('/admin/news', data, { loading: true })
export const newsUpdate = data => {
  if (data.id) {
    return request.put(`/admin/news/${data.id}`, data, { loading: true })
  }
  return request.post('/admin/news', data, { loading: true })
}
export const newsDelete = id => {
  if ('number' === typeof id) {
    return request.delete(`/admin/news/${id}`, {}, { loading: true })
  }
  return request.delete(`/admin/news/batch`, { id }, { loading: true })
}
